package com.yuan.gather.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Mapping;
import org.springframework.data.elasticsearch.annotations.Setting;

import javax.persistence.Id;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 资产最新的采集结果
 *
 * @author zhaoff
 */
@Getter
@Setter
@Document(indexName = "gather-asset")
@Mapping(mappingPath = "/com/yuan/gather/entity/gather-asset.json")
@Setting(settingPath = "/com/yuan/gather/gather-settings.json")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class GatherAsset implements Serializable {

    private static final long serialVersionUID = 4633301890630279597L;

    /**
     * 采集资产 ID
     */
    @Id
    private String id;

    /**
     * 资产ID，对应 mysql 中存储的资产主键
     */
    private Integer devId;

    /**
     * 资产名称
     */
    private String name;

    /**
     * 资产 ip
     */
    private String ip;

    /**
     * 资产类型
     */
    private Integer assetType;

    /**
     * 系统类型，对应tbl_dev
     */
    private String sysType;

    /**
     * 系统类型ID，对应tbl_dev
     */
    private Integer sysTypeId;

    /**
     * 任务类型
     */
    private String taskType;

    /**
     * 业务类型
     */
    private String servsys;

    /**
     * 资产版本
     */
    private String version;

    /**
     * 风险级别
     */
    private Integer level = 0;

    /**
     * 资产状态
     */
    private Integer status = 0;

    /**
     * 资产数据是否拼装完成
     */
    private boolean integrated;

    /**
     * 标记是否是快照
     */
    private boolean snapshotFlag;

    /**
     * 最近一次配置有变更的子类型任务采集日志ID
     */
    private String lastDevLog;

    /**
     * 风险视图统计信息id
     */
    @JsonProperty("riskviewdevstatistics")
    private String riskViewDevStatistics;

    /**
     * 资产采集时间，记录最近一次更新时间
     */
    private Long utime;

    /**
     * 资产详情
     */
    private Map<String, Object> details = new HashMap<>();

    /** 采集信息，为方便查询和获取信息，对一些信息进行提取 */
    /**
     * 备份数据id  "backup":String
     */
    private Map<String, Object> gatherInfo = new HashMap<>();

    @JsonProperty("assetsnapshot")
    private List<String> snapshot = new ArrayList<>();

    /**
     * 最新的快照的ID
     */
    private String lastSnapshot;

    /**
     * 变化类型
     */
    private List<String> changeKey = new ArrayList<>();

    /**
     * 数量最多的三种变化类型和数量的映射
     */
    private Map<String, Object> mostChange = new HashMap<>();

    /**
     * 资产信息转快照，快照删除维护日志
     */
    /*public void change2Snapshot() {
        this.snapshotFlag = true;
        this.setRiskViewDevStatistics(null);
        this.id = null;
        this.getDetails().remove(GatherConstants.ES_TYPE_MAINTENANCE_LOG);
    }*/

}
